package com.tom.chain_of_responsibility.v2.factory;

import com.tom.chain_of_responsibility.model.req.UserSearchReq;
import com.tom.chain_of_responsibility.v2.IRequestHandler;
import org.springframework.util.Assert;

import java.util.List;

//@Component
public class RequestHandlerFactory {
    private IRequestHandler first;



    public RequestHandlerFactory(List<IRequestHandler> requestHandlers){
        Assert.notEmpty(requestHandlers, "requestHandlers can not be empty");
        for(int i =0;i<requestHandlers.size()-1;i++){
            requestHandlers.get(i).setNext(requestHandlers.get(i+1));
        }
        first = requestHandlers.get(0);
    }

    public Boolean executeHandler(UserSearchReq userSearchReq) {
        return first.handleRequest(userSearchReq);
    }


}
